package com.test.webtest.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.test.webtest.dto.Result;
import com.test.webtest.entity.Site;
import com.test.webtest.service.SiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sites")
public class SiteController {

    @Autowired
    private SiteService siteService;

    /**
     * 分页查询接口
     * @param page 页码（默认1）
     * @param pageSize 每页数量（默认10）
     */
    @GetMapping
    public Result list(
            @RequestParam(defaultValue = "1") Integer page,
            @RequestParam(defaultValue = "10") Integer pageSize
            ) {

        Page<Site> resultPage = siteService.pageQuery(page,pageSize);

        return Result.ok(resultPage.getRecords(),resultPage.getTotal());
    }

    /**
     * 站点详情查询
     * @param id 站点ID
     */
    @GetMapping("/{id}")
    public Result detail(@PathVariable Integer id) {

        return Result.ok(siteService.detail(id));
    }
}